---

apiVersion: v1
kind: Service
metadata:
  name: worker
  namespace: {{ .Values.namespace }}
spec:
  ports:
    - name: worker-server-port
      port: 50051
      targetPort: 50051
  selector:
    app: worker-server
  type: ClusterIP

---


apiVersion: apps/v1
kind: Deployment
metadata:
  name: worker
  namespace: {{ .Values.namespace }}
spec:
  replicas: 2
  selector:
    matchLabels:
      app: worker
  template:
    metadata:
      labels:
        app: worker
        member-type: worker
    spec:
      serviceAccountName: worker-serviceaccount
      containers:
        - name: worker
          image: worker
          imagePullPolicy: IfNotPresent
          command: ["cargo", "run"]
          ports:
            - containerPort: 50051
          volumeMounts:
            - name: chroma
              mountPath: /index_data
          env:
            - name: CHROMA_WORKER__PULSAR_URL
              value: pulsar://pulsar.chroma:6650
            - name: CHROMA_WORKER__MY_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
      topologySpreadConstraints:
        - maxSkew: 1
          topologyKey: "kubernetes.io/hostname"
          whenUnsatisfiable: ScheduleAnyway
          labelSelector:
            matchLabels:
              member-type: worker
      volumes:
        - name: chroma
          emptyDir: {}

---

apiVersion: v1
kind: ServiceAccount
metadata:
  name: worker-serviceaccount
  namespace: {{ .Values.namespace }}

---

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: worker-serviceaccount-rolebinding
  namespace: {{ .Values.namespace }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: pod-watcher
subjects:
- kind: ServiceAccount
  name: worker-serviceaccount
  namespace: {{ .Values.namespace }}

---